using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Brand.Dto;
using JTZY.Model.Brand;
using JTZY.Service.Brand.IBrandService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2024-11-01
namespace JTZY.Admin.WebApi.Controllers.Brand
{
    /// <summary>
    /// 品牌表
    /// </summary>
    [Verify]
    [Route("brand/Corecmsbrand")]
    public class CorecmsbrandController : BaseController
    {
        /// <summary>
        /// 品牌表接口
        /// </summary>
        private readonly ICorecmsbrandService _CorecmsbrandService;

        public CorecmsbrandController(ICorecmsbrandService CorecmsbrandService)
        {
            _CorecmsbrandService = CorecmsbrandService;
        }

        /// <summary>
        /// 查询品牌表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "corecmsbrand:list")]
        public IActionResult QueryCorecmsbrand([FromQuery] CorecmsbrandQueryDto parm)
        {
            var response = _CorecmsbrandService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询品牌表列表（无分页）
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("all")]
        [ActionPermissionFilter(Permission = "corecmsbrand:list")]
        public IActionResult QueryCorecmsAllbrand([FromQuery] CorecmsbrandQueryDto parm)
        {
            var response = _CorecmsbrandService.GetAllList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询品牌表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "corecmsbrand:query")]
        public IActionResult GetCorecmsbrand(int Id)
        {
            var response = _CorecmsbrandService.GetInfo(Id);
            
            var info = response.Adapt<CorecmsbrandDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加品牌表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "corecmsbrand:add")]
        [Log(Title = "品牌表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCorecmsbrand([FromBody] CorecmsbrandDto parm)
        {
            var modal = parm.Adapt<Corecmsbrand>().ToCreate(HttpContext);

            var response = _CorecmsbrandService.AddCorecmsbrand(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新品牌表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "corecmsbrand:edit")]
        [Log(Title = "品牌表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCorecmsbrand([FromBody] CorecmsbrandDto parm)
        {
            var modal = parm.Adapt<Corecmsbrand>().ToUpdate(HttpContext);
            var response = _CorecmsbrandService.UpdateCorecmsbrand(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除品牌表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "corecmsbrand:delete")]
        [Log(Title = "品牌表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCorecmsbrand([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CorecmsbrandService.Delete(idArr));
        }

    }
}